package org.gjy.m8.date;

import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author gjy
 * @version 1.0
 * @since 2024-01-25 11:20:13
 */
public class CalendarTest {

    @Test
    public void test2() {
        String a = null;
        System.out.println(a + "hello");
    }

    @Test
    public void test1() {
        String lastMonth = getLastMonth();
        System.out.println("lastMonth = " + lastMonth);
    }

    public static String getLastMonth() {
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月");
        Calendar calendar = Calendar.getInstance();
        // 设置为当前时间
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, -1);
        return format.format(calendar.getTime());
    }
}
